<template>
    <div id="report">
        <div class="card-container">
            <el-row :gutter="10">
            <el-form :model="queryParams" label-width="100px" ref="queryForm" :inline="true">
                <el-col :span="19" :offset="0">
                    <el-form-item label="省" prop="province">
                        <el-input v-model="queryParams.province" :style="'width:215px'" placeholder="请输入省" clearable
                            size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item label="市" prop="city">
                        <el-input v-model="queryParams.city" :style="'width:215px'" placeholder="请输入市" clearable
                            size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item label="预警类型" prop="signalType">
                        <el-select v-model="queryParams.signalType" clearable :style="'width:215px'" placeholder="请选择所属项目">
                            <el-option :value="item" :label="item" v-for="(item, index) in signalOptions"
                                :key="index + 'type'">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="预警等级" prop="signalLevel">
                        <el-select v-model="queryParams.signalLevel" clearable :style="'width:215px'" placeholder="请选择所属项目">
                            <el-option :value="item" :label="item" v-for="(item, index) in levelOptions"
                                :key="index + 'level'">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="时间" prop="time">
                        <span @click.once="changeInitCalendarPage" class="date-box">
                            <el-date-picker v-model="queryParams.time" type="datetimerange" range-separator="至"
                                start-placeholder="开始日期" end-placeholder="结束日期" value-format="timestamp"
                                :picker-options="pickerOptions">
                            </el-date-picker>
                        </span>
                    </el-form-item>
                </el-col>
                <el-col :span="5" :offset="0">
                    <el-form-item>
                        <el-button  icon="el-icon-search" size="mini" @click="handleQuery">搜索
                        </el-button>
                        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        </div>
       
        <div class="card-container">
            <el-table :data="weatherList" :row-class-name="tableRowClassName">
                <el-table-column prop="head" align="center" show-overflow-tooltip label="事件" min-width="150" />
                <el-table-column prop="address" align="center" show-overflow-tooltip label="预警范围" min-width="120">
                </el-table-column>
                <el-table-column prop="signalType" align="center" show-overflow-tooltip label="预警类型" min-width="60" />
                <el-table-column prop="signalLevel" align="center" show-overflow-tooltip label="预警等级" min-width="60" />
                <el-table-column prop="issueTime" align="center" show-overflow-tooltip label="预警时间" min-width="120" />
                <el-table-column prop="relieveTime" align="center" show-overflow-tooltip label="解除时间" min-width="120" />
                <el-table-column prop="issueContent" align="center" show-overflow-tooltip label="预警内容" min-width="200" />
                <el-table-column prop="standar" align="center" show-overflow-tooltip label="预警标准" min-width="200" />
                <el-table-column prop="defenseGuide" align="center" show-overflow-tooltip label="防御指南" min-width="200">
                    <template slot-scope="scope">
                        <span>{{ scope.row.defenseGuide }}</span>
                    </template>

                </el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div>
    </div>
</template>

<script>
import { getWeatherWarning } from '@/api/weather/index.js'
import moment from 'moment';
export default {
    name: "weather",
    dicts: [
        "sys_log_type",
        "sys_report_type"
    ],
    data() {
        return {
            weatherList: [],
            total: 0,
            queryParams: { pageNum: 1, pageSize: 10, province: null, city: null, signalType: null, signalLevel: null, time: null, startTime: null, endTime: null },
            signalOptions: ['高温', '大风', '雷电', '暴雨', '强对流', '冰雹', '雷雨大风', '大雾', '海上大风', '雷暴大风', '沙尘暴', '海上雷雨大风', '海上雷电', '海上大雾'],
            levelOptions: ['蓝色', '黄色', '橙色', '红色'],
            pickerOptions: {
                //禁用当前日期之前的日期
                disabledDate(time) {
                    //Date.now()是javascript中的内置函数，它返回自1970年1月1日00:00:00 UTC以来经过的毫秒数。
                    return time.getTime() > Date.now();
                },
            },
        }
    },
    created() {
        this.getList()
    },
    methods: {
        tableRowClassName({ row, rowIndex }) {
            // if (Number(row.magnitude) >= 6) {
            //     return 'warning-row';
            // }
            // return '';
        },
        async getList() {
            const res = await getWeatherWarning(this.queryParams)
            if (res.code == 200) {
                this.weatherList = res.rows
                this.total = res.total
            }
        },
        changeInitCalendarPage() {
            console.log("123");
            let element = document.querySelectorAll(
                ".el-picker-panel__icon-btn.el-icon-arrow-left"
            )
            console.log(element, 'element')
            if (element) element[element.length - 1].click();
        },

        handleQuery() {
            if (this.queryParams.time) {
                this.queryParams.startTime = this.queryParams.time[0]
                this.queryParams.endTime = this.queryParams.time[1]
            } else {
                this.queryParams.startTime = null
                this.queryParams.endTime = null
            }
            this.queryParams.pageNum = 1;
            this.getList()
        },
        resetQuery() {
            this.queryParams.startTime = null
            this.queryParams.endTime = null
            this.resetForm("queryForm");
            this.handleQuery();
        }
    }
}
</script>

<style>
#report {
    width: 100%;
    height: 100%;
    padding: 20px;
    position: relative;
    box-sizing: border-box;
}

.el-table .warning-row {
    /* background: linear-gradient(to right, #FFAAAA 0%, #ff4444 100%); */
    color: #ff4444;
}

.date-box {
    display: inline-block;
    height: 100%;
    z-index: 1;
}
</style>